package com.utcook.host.fragmentdialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.utcook.host.fragmentdialog.databinding.FragmentRecipeListBinding

class RecipeListFragment : Fragment() {

    private var _binding: FragmentRecipeListBinding? = null
    private val binding get() = _binding!!
    private var burnerViewModel: BurnerViewModel? = null

    companion object {
        fun newInstance(viewModel: BurnerViewModel): RecipeListFragment {
            val fragment = RecipeListFragment()
            fragment.burnerViewModel = viewModel
            return fragment
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentRecipeListBinding.inflate(inflater, container, false)
        
        setupRecipeList()
        
        return binding.root
    }

    private fun setupRecipeList() {
        burnerViewModel?.let { viewModel ->
            val recipeAdapter = RecipeAdapter(viewModel.recipes.toList()) { recipe ->
                viewModel.selectRecipe(recipe)
            }
            binding.recipeRecyclerView.adapter = recipeAdapter
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
} 